// /*
// * To change this template, choose Tools | Templates
// * and open the template in the editor.
// */
//package br.com.foxline.manager.create;
//
//import br.com.foxline.enums.*;
//import br.com.foxline.model.*;
//import br.com.foxline.service.*;
//import br.com.foxline.util.*;
//import br.com.foxline.vo.*;
//import java.io.*;
//import java.util.*;
//import javax.annotation.PostConstruct;
//import javax.ejb.EJB;
//import javax.faces.bean.*;
//import javax.faces.context.FacesContext;
//import javax.faces.model.SelectItem;
//import org.primefaces.event.FileUploadEvent;
//
///**
// * 
// * @author ely
// */
//@ManagedBean
//@ViewScoped
//public class ManagerCreateRequirement implements Serializable {
//
//    @EJB
//    RequirementService requirementService;
//    @EJB
//    AnnexService annexService;
//    @EJB
//    PeopleService peopleService;
//    @EJB
//    AddressService addressService;
//   
//    
//    private Requirement requirement;
//    private Annex annex;
//    private List<Annex> annexs;
//    private Annex a;
//    private Requirement requirementRel;
//    private String reqAve;
//    private String reqRev;
//    private String reqHab;
//    private String reqAlv;
//    private String index;
//    private boolean disableAnnexButton;
//    private boolean readOnlyInputs;
//    private boolean readOnlyInputsAddress;
//    private People proprietary;
//    private Address address;
//    private People interested;
//   
//
//    @PostConstruct
//    public void init() {
//        requirement = new Requirement();
//        annexs = new ArrayList<Annex>();
//        annex = new Annex();
//        a = new Annex();
//        proprietary = new People();
//        proprietary.setTypeDocument(TypeDocument.CPF);
//        interested = new People();
//        interested.setTypeDocument(TypeDocument.CPF);
//        readOnlyInputs = false;
//        address = new Address();
//        disableAnnexButton = true;
//       
//
//       
//       
//
//        Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
//        reqAve = params.get("reqAve");
//        reqRev = params.get("reqRev");
//        reqHab = params.get("reqHab");
//        reqAlv = params.get("reqAlv");
//        index = params.get("index");
//        paramPost();
//    }
//
//    public void reinit() {
//        requirement = new Requirement();
//        annexs = new ArrayList<Annex>();
//        annex = new Annex();
//        a = new Annex();
//    }
//
//    public List<SelectItem> getTypeRequeriment() {
//        List<SelectItem> r = new ArrayList<SelectItem>();
//        for (TypeRequirement ms : TypeRequirement.values()) {
//            r.add(new SelectItem(ms, ms.getName()));
//        }
//        return r;
//    }
//
//    public List<SelectItem> getTypePatio() {
//        List<SelectItem> r = new ArrayList<SelectItem>();
//        for (TypePatio ms : TypePatio.values()) {
//            r.add(new SelectItem(ms, ms.getName()));
//        }
//        return r;
//    }
//
//    public List<SelectItem> getStatus() {
//        List<SelectItem> s = new ArrayList<SelectItem>();
//        for (Status ms : Status.values()) {
//            s.add(new SelectItem(ms, ms.getName()));
//        }
//        return s;
//    }
//
//    public List<SelectItem> getTypeAnnex() {
//        List<TypeAnnex> typeAnnexs = requirementService.typeAnnex(requirement);
//        List<SelectItem> t = new ArrayList<SelectItem>();
//        for (TypeAnnex ta : typeAnnexs) {
//            t.add(new SelectItem(ta, ta.getName()));
//        }
//        return t;
//    }
//
//    public List<SelectItem> getTypeQuality() {
//
//        List<SelectItem> t = new ArrayList<SelectItem>();
//        for (TypeQuality ta : TypeQuality.values()) {
//            t.add(new SelectItem(ta, ta.getName()));
//        }
//        return t;
//    }
//
//    public List<SelectItem> typeDocumentList() {
//        List<SelectItem> items = new ArrayList<SelectItem>();
//        for (TypeDocument tipo : TypeDocument.values()) {
//            if (tipo != TypeDocument.OAB) {
//                items.add(new SelectItem(tipo.getType(), tipo.getName()));
//            }
//        }
//        return items;
//    }
//
//    public void paramPost() {
//        try {
//            if (reqAve != null) {
//                requirement.setType_requeriment(TypeRequirement.AVERBACAO);
//            } else if (reqRev != null) {
//                requirement.setType_requeriment(TypeRequirement.REVISAO_ALINHAMENTO);
//            } else if (reqHab != null) {
//                requirement.setType_requeriment(TypeRequirement.HABITE);
//            } else if (reqAlv != null) {
//                requirement.setType_requeriment(TypeRequirement.ALVARA_CONSTRUCAO);
//            } else if (index != null) {
//            }
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//    }
//
//    public void saveRequeriment() {
//
//        if (proprietary.getId() == null) {
//            proprietary.setName(proprietary.getName());
//            peopleService.removeCaracterDocument(proprietary);
//            Address addres = new Address();
//            proprietary.setAddress(addres);
//            //addressService.save(proprietary.getAddress());
//            peopleService.save(proprietary);
//            requirement.setOwner(proprietary);
//            setAddressRequirement(requirement);
//        } else {
//            requirement.setOwner(proprietary);
//           
//        } 
//
//        setAddressRequirement(requirement);
//        requirementRel = requirement;
//        requirementService.saveRequirement(requirement, annexs);
//
//        org.primefaces.context.RequestContext.getCurrentInstance().execute("dlg.show();");
//        init();
//    }
//
//    public void setAddressRequirement(Requirement req) {
//        req.setAddressImovel(address.getPatio());
//        req.setNeighborhoodImovel(address.getDistrict());
//        req.setZipCodeNeighborhood(address.getCep());
//    } 
//
//    public void existProprietary() {
//        peopleService.removeCaracterDocument(proprietary);
//        if (proprietary.getTypeDocument() == TypeDocument.CPF) {
//            if (proprietary.getCpf().equals("")) {
//                proprietary = new People();
//                proprietary.setTypeDocument(TypeDocument.CPF);
//            } else {
//                proprietary = requirementService.existDocuments(proprietary);
//            }
//             readOnlyInputs = proprietary.getId() != null;
//        } else if (proprietary.getTypeDocument() == TypeDocument.CNPJ) {
//            if (proprietary.getCnpj().equals("")) {
//                proprietary = new People();
//                proprietary.setTypeDocument(TypeDocument.CNPJ);
//            } else {
//                proprietary = requirementService.existDocuments(proprietary);
//            }
//            readOnlyInputs = proprietary.getId() != null;
//        }
//      
//    }
//
//    
//    /**
//     * Verifica se existe um endereço para o CEP informado
//     */
//    public void existAddress() {
//        Address a = new Address();
//        a = this.addressService.existCep(address);
//        if (a != null) {
//            address = a;
//        }
//    }
//
//    public void ajaxTypeAnnex() {
//        annexService.ajaxTypeAnnex(annex, a);
//        if (annex.getType_annex() != null) {
//            disableAnnexButton = false;
//        } else {
//            disableAnnexButton = true;
//        }
//    }
//
//    public void removeAnnex(int a, Annex an) {
//        try {
//            annexs.remove(a);
//            annexService.delete(an);
//            Msg.messagemInfo("Documento Excluído");
//        } catch (Exception erro) {
//            erro.printStackTrace();
//        }
//    }
//
//    public void handle(FileUploadEvent event) throws IOException {
//        handleAux(event.getFile().getContents(), event.getFile().getFileName(),
//                event.getFile().getContentType(), event.getFile().getInputstream());
//    }
//
//    private void handleAux(byte[] imageBytes, String nome, String tipo, InputStream is) throws IOException {
//
//        byte[] bytes = null;
//        annex = new Annex();
//        bytes = imageBytes;
//        annex.setType(tipo);
//        annex.setDescription(nome);
//
//        if (bytes != null) {
//            annex.setFileByte(bytes);
//            annex.setType_annex(a.getType_annex());
//            annexService.save(annex);
//            annexs.add(annex);
//            
//
//            annex = new Annex();
//
//            Msg.messagemInfo("Anexado com Sucesso");
//        }
//    }
//
//    public void reportRequiriment(Requirement requirement) {
//        ReportRequirementVO reportVO = new ReportRequirementVO();
//
//        HashMap<String, Object> h = new HashMap<String, Object>();
//
//        String img = "bandeira.jpg";
//        String reportPath = FacesContext.getCurrentInstance().getExternalContext().getRealPath("/media/images/" + img);
//
//        // Tipo Requerimento
//        reportVO.setType_req(Caracter.removecaracter(requirementRel.getType_requeriment().getName()));
//
//        // Intessado
//        reportVO.setName(requirementRel.getInterested());
//        reportVO.setCpf(requirementRel.getCpfInterested());
//        reportVO.setPatio(requirementRel.getAddressInterested());
//        reportVO.setDistrict(requirementRel.getNeighborhoodInterested());
//        reportVO.setNum(requirementRel.getNumInterested());
//        String cep_interessado      = requirementRel.getZipCodeNeighborhood();
//        // Telefone
//        // Fax
//
//        // Imóvel
//        reportVO.setAddressImovel(requirementRel.getAddressImovel());
//        reportVO.setFoneImovel(requirementRel.getFoneImovel());
//        reportVO.setNeighborhoodImovel(requirementRel.getNeighborhoodImovel());
//        reportVO.setNumberImovel(requirementRel.getNumberImovel());
//        reportVO.setZipCodeNeighborhood(requirementRel.getZipCodeNeighborhood());
//        reportVO.setObs(requirementRel.getObs());
//
//        if (requirementRel.getOwner().getTypeDocument() == TypeDocument.CPF) {
//
//            reportVO.setName_p(requirementRel.getOwner().getName());
//            reportVO.setDoc_p(requirementRel.getOwner().getCpf());
//            reportVO.setEnd_p(requirementRel.getOwner().getAddress().getPatio());
//            reportVO.setDist_p(requirementRel.getOwner().getAddress().getDistrict());
//            reportVO.setN_p(requirementRel.getOwner().getAddress().getNum());
//            reportVO.setCep_p(requirementRel.getOwner().getAddress().getCep());
//        }
//        if (requirementRel.getOwner().getTypeDocument() == TypeDocument.CNPJ) {
//
//            reportVO.setName_p(requirementRel.getOwner().getName_fantasy());
//            reportVO.setDoc_p(requirementRel.getOwner().getCnpj());
//            reportVO.setEnd_p(requirementRel.getOwner().getAddress().getPatio());
//            reportVO.setDist_p(requirementRel.getOwner().getAddress().getDistrict());
//            reportVO.setN_p(requirementRel.getOwner().getAddress().getNum());
//            reportVO.setCep_p(requirementRel.getOwner().getAddress().getCep());
//        }
//
//        h.put("tipo_req", reportVO.getType_req());
//        h.put("nome_interessado", reportVO.getName());
//        h.put("cpf_cnpj_interessado", reportVO.getCpf());
//        h.put("endereco_interessado", reportVO.getPatio());
//        h.put("bairro_interessado", reportVO.getDistrict());
//        h.put("n_interessado", reportVO.getNum());
//        h.put("nome_proprietario", reportVO.getName_p());
//        h.put("cpf_cnpj_proprietario", reportVO.getDoc_p());
//        h.put("endereco_proprietario", reportVO.getEnd_p());
//        h.put("bairro_proprietario", reportVO.getDist_p());
//        h.put("n_proprietario", reportVO.getN_p());
//        h.put("cep_proprietario", reportVO.getCep_p());
//        h.put("img", reportPath);
//        h.put("endereco_imovel", reportVO.getAddressImovel());
//        h.put("bairro_imovel", reportVO.getNeighborhoodImovel());
//        h.put("telefone_imovel", reportVO.getFoneImovel());
//        h.put("cep_imovel", reportVO.getZipCodeNeighborhood());
//        h.put("especificacao_imovel", reportVO.getObs());
//        h.put("n_imovel", reportVO.getNumberImovel());
//
//        requirementService.reportsRequirement(requirement, h);
//    }
//
//    public void showReport() {
//        reportRequiriment(requirementRel);
//    }
//
//    public Requirement getRequirement() {
//        return requirement;
//    }
//
//    public void setRequirement(Requirement requirement) {
//        this.requirement = requirement;
//    }
//
//    public Annex getAnnex() {
//        return annex;
//    }
//
//    public void setAnnex(Annex annex) {
//        this.annex = annex;
//    }
//
//    public List<Annex> getAnnexs() {
//        return annexs;
//    }
//
//    public void setAnnexs(List<Annex> annexs) {
//        this.annexs = annexs;
//    }
//
//    public boolean isDisableAnnexButton() {
//        return disableAnnexButton;
//    }
//
//    public void setDisableAnnexButton(boolean disableAnnexButton) {
//        this.disableAnnexButton = disableAnnexButton;
//    }
//
//    public boolean isReadOnlyInputs() {
//        return readOnlyInputs;
//    }
//
//    public void setReadOnlyInputs(boolean readOnlyInputs) {
//        this.readOnlyInputs = readOnlyInputs;
//    }
//
//    public boolean isReadOnlyInputsAddress() {
//        return readOnlyInputsAddress;
//    }
//
//    public void setReadOnlyInputsAddress(boolean readOnlyInputsAddress) {
//        this.readOnlyInputsAddress = readOnlyInputsAddress;
//    }
//
//    public People getProprietary() {
//        return proprietary;
//    }
//
//    public void setProprietary(People proprietary) {
//        this.proprietary = proprietary;
//    }
//
//    public Address getAddress() {
//        return address;
//    }
//
//    public void setAddress(Address address) {
//        this.address = address;
//    }
//
//    public People getInterested() {
//        return interested;
//    }
//
//    public void setInterested(People interested) {
//        this.interested = interested;
//    }
//
//   
//}
